// miniprogram/pages/consumption/all/all.js
const db = wx.cloud.database()
const _ = db.command
const $ = _.aggregate
Page({
  data: {
    list: [],
    monthMoney: '0.00',
    nowMonth: 0,
    className: 'green-border'
  },
  onLoad: function (options) {
    wx.showLoading({
      title: '正在加载...'
    })
    this.setData({
      nowMonth: new Date().getMonth() + 1
    })
  },
  onShow: function () {
    this.initData()
  },
  initData: function(){
    wx.cloud.callFunction({
      name: 'consume',
      data: {
        action: 'consume_all'
      },
      success: res => {
        wx.hideLoading()
        let list = res.result
        list.map(item => {
          if (item._id == this.data.nowMonth) {
            this.setData({
              monthMoney: item.money,
              className: item.className
            })
          }
        })
        this.setData({
          list: list,
          isLoading: true
        })
      },
      fail: err => {
        wx.hideLoading()
      }
    })
  },
  go: function (e) {
    let url = e.currentTarget.dataset.url
    wx.navigateTo({
      url: url
    })
  }
})